package com.sk.bilibili.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sk.bilibili.bean.Type;
import com.sk.bilibili.bean.VideoSet;
import com.sk.bilibili.dto.VideoSetInfo;
import com.sk.bilibili.other.R;
import com.sk.bilibili.service.VideoSetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 邵康
 * @date 2021/11/23 16:10
 */
@CrossOrigin
@RestController
@Api(tags = "视频集")
@RequestMapping("/videoSet")
public class VideoSetController {

    @Autowired
    private VideoSetService videoSetService;

    @ApiOperation("创建视频集,title,coverFile,type是必须的  会触发动态更新")
    @PostMapping("/add")
    public R<Void> add(VideoSet videoSet) {
        return videoSetService.add(videoSet);
    }

//    @ApiOperation("转发视频,VideoSetId,转发评论必须")
//    @GetMapping("/forward")
//    public R<Void> forward(Integer id,String content,HttpSession session){
//        return videoSetService.forward(id,content,session);
//    }

    @ApiOperation("deleteRes")
    @GetMapping("/delete")
    public R<Void> delete(Integer id) {
        return videoSetService.delete(id);
    }

    @ApiOperation("update")
    @PostMapping("/update")
    public R<Void> update(VideoSet videoSet) {
        return videoSetService.update(videoSet);
    }

    @ApiOperation("根据typeId  进行分页  typeId指定类型Id")
    @GetMapping("/page")
    public R<IPage<VideoSet>> page(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer size,
                                   @RequestParam(required = false)Integer typeId) {
        return videoSetService.page(page, size,typeId);
    }

    @ApiOperation("随机获取指定数目个 typeId类型必须  0是主页的  size默认为6")
    @GetMapping("/getRandom")
    public R<List<VideoSet>> getRandom(@RequestParam(defaultValue = "6") Integer size,Integer typeId) {
        return videoSetService.getRandom(size,typeId);
    }

    @ApiOperation("按排名获取指定数目个 typeId类型必须  主页为null  size默认为10")
    @GetMapping("/getRank")
    public R<List<VideoSet>> getRank(@RequestParam(defaultValue = "10") Integer size,
                                     @RequestParam(required = false)Integer typeId) {
        return videoSetService.getRank(size,typeId);
    }

    @ApiOperation("获取用户的投稿视频")
    @PostMapping("/getVideoSets")
    public R<IPage<VideoSet>> getVideoSets(@RequestBody VideoSetInfo videoSetInfo){
        return videoSetService.getVideoSets(videoSetInfo);
    }

    @ApiOperation("根据视频Id获取视频详细信息  包含 用户 所有视频信息")
    @GetMapping("/getVideoSet")
    public R<VideoSet> getVideoSet(Integer videoSetId){
        return videoSetService.getVideoSet(videoSetId);
    }

    @ApiOperation("搜索指定用户的投稿视频")
    @PostMapping("/searchVideoSets")
    public R<IPage<VideoSet>> searchVideoSets(@RequestBody VideoSetInfo videoSetInfo){
        return videoSetService.searchVideoSets(videoSetInfo);
    }

    @ApiOperation("获取搜索视频时的各类型数量信息 用户id  关键字必须")
    @PostMapping("/getSearchType")
    public R<List<Type>> getSearchType(@RequestBody VideoSetInfo videoSetInfo){
        return videoSetService.getSearchType(videoSetInfo);
    }

}
